home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 April: Mac OS SDK / Dev.CD Apr 97 SDK1.toast / Development Kits (Disc 1) / Apple Shared Library Manager / ASLM Examples / Inspector / Sources / Document.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-11-19  |  5.0 KB  |  167 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        TDocument.h
  3.  
  4.     Contains:    TDocument interface
  5.  
  6.     Copyright:    © 1991-1994 by Apple Computer, Inc., all rights reserved.
  7.  
  8. */
  9.  
  10.  
  11. #ifndef __DOCUMENT__
  12. #define __DOCUMENT__
  13.  
  14. #ifndef __LIBRARYMANAGERCLASSES__
  15. #include <LibraryManagerClasses.h>
  16. #endif
  17.  
  18.  
  19. /*******************************************************************************
  20. ** Forward declarations
  21. ********************************************************************************/
  22.  
  23. class TDocument;
  24. class TDocumentLink;
  25. class TDocumentList;
  26. struct EventRecord;
  27. struct GrafPort;
  28.  
  29.  
  30. // Define HiWrd and LoWrd macros for efficiency
  31. #define HiWrd(aLong)    ((short) (((aLong) >> 16) & 0xFFFF))
  32. #define LoWrd(aLong)    ((short) ((aLong) & 0xFFFF))
  33.  
  34. // Define TopLeft and BotRight macros for convenience. Notice the implicit
  35. // dependency on the ordering of fields within a Rect
  36. #define TopLeft(aRect)    (* (Point *) &(aRect).top)
  37. #define BotRight(aRect)    (* (Point *) &(aRect).bottom)
  38.  
  39. const long kMaxSleepTime = 60;    // 1 second worth of ticks
  40.  
  41. /**********************************************************************
  42. ** class TDocument
  43. ***********************************************************************/
  44.  
  45. #define kTDocumentID "appl:insp$TDocument,1.2"
  46.  
  47. class TDocument : public TDynamic
  48. {
  49. public:
  50.                 TDocument();
  51.                 TDocument(short resID);        // creates window using resID as template
  52.     virtual        ~_CDECL TDocument();                // disposes of window
  53.  
  54.     // you will need to override these in your subclasses,
  55.     // since they are do-nothing routines by default...
  56.     virtual void        DoZoom(short partCode);
  57.     virtual void        DoGrow(EventRecord* theEvent);
  58.     virtual void        DoContent(EventRecord* theEvent);
  59.     virtual void        DoKeyDown(EventRecord* theEvent);
  60.     virtual void        DoActivate(Boolean becomingActive);
  61.     virtual void        DoUpdate();
  62.     // file handling routines
  63.     virtual void        DoOpen();
  64.     virtual void        DoClose();
  65.     virtual void        DoSave();
  66.     virtual void        DoSaveAs();
  67.     virtual void        DoRevert();
  68.     virtual void        DoPrint();
  69.     // do standard edit menu actions
  70.     virtual void        DoUndo();
  71.     virtual void        DoCut();
  72.     virtual void        DoCopy();
  73.     virtual void        DoPaste();
  74.     virtual void        DoClear();
  75.     virtual void        DoSelectAll();
  76.  
  77.     // idle time routines: you can use these to do cursor handling,
  78.     // TE caret blinking, marquee effects, etc...
  79.     virtual void            DoIdle();
  80.     virtual unsigned long    CalcIdle();
  81.     virtual void            AdjustCursor(Point where);            // where is in local coords
  82.  
  83.     // query state of document - useful for adjusting menu state
  84.     virtual Boolean            HaveUndo();
  85.     virtual Boolean            HaveSelection();
  86.     virtual Boolean            HavePaste();
  87.     virtual Boolean            CanClose();
  88.     virtual Boolean            CanSave();
  89.     virtual Boolean            CanSaveAs();
  90.     virtual Boolean            CanRevert();
  91.     virtual Boolean            CanPrint();
  92.  
  93.             GrafPort*        GetDocWindow() { return fDocWindow;} ;
  94.             TDocumentList*    GetDocList() { return fDocList; };
  95.             void            SetDocList(TDocumentList *theDocList) { fDocList = theDocList; };
  96.     
  97. protected:
  98.     GrafPort*         fDocWindow;
  99.     TDocumentList    *fDocList;
  100.  
  101. private:
  102.     virtual    void        InitDocument(short resID);
  103. };
  104.  
  105.  
  106. /**********************************************************************
  107. ** class TDocumentList
  108. ***********************************************************************/
  109.  
  110. #define kTDocumentListID "appl:insp$TDocumentList,1.2"
  111.  
  112. // TDocumentList is a simple linked list of documents, implemented C++
  113. // style. I could have made a general linked list class & just made
  114. // this a subclass. This would have been a more general (and more
  115. // object-oriented) solution, but I did it from scratch in a futile
  116. // attempt at keeping the size of this program at a reasonable level.
  117.  
  118. class TDocumentList : public TDynamic
  119. {
  120.     TDocumentLink*    fDocList;    // the first link in our list
  121.     int                fNumDocs;    // the number of elements in the list
  122.  
  123. public:
  124.                             TDocumentList();    // our constructor
  125.     virtual                    ~_CDECL TDocumentList();    // our destructor
  126.  
  127.     virtual void            AddDoc(TDocument* doc);
  128.     virtual void            RemoveDoc(TDocument* doc);
  129.     virtual TDocument*        FindDoc(GrafPort* window);
  130.     inline int                NumDocs() { return fNumDocs; }
  131.     inline TDocumentLink*    FirstDoc() { return fDocList; }
  132. };
  133.  
  134.  
  135. /**********************************************************************
  136. ** class TDocumentLink
  137. ***********************************************************************/
  138.  
  139. // TDocumentLink is a simple utility class which is used by
  140. // the TDocumentList class below. You cannot allocate
  141. // objects of this type yourself, since its constructor
  142. // is private. We get around this for TDocumentList by
  143. // making it a "friend" of this class. This is a handy
  144. // trick.
  145. class TDocumentLink : public TLink
  146. {
  147.     friend class TDocumentList;
  148.  
  149.     // our constructor. Note that it can take args for convenience,
  150.     // but that they default to NULL.
  151.                             TDocumentLink(TDocumentLink *n = NULL, TDocument *v = NULL);
  152.                             ~TDocumentLink() {};
  153.  
  154.             void             SetDoc(TDocument* aDoc) { SetValue(aDoc); };
  155.  
  156. public:
  157.             TDocumentLink*    GetNext() { return (TDocumentLink*)TLink::GetNext(); };
  158.             TDocument*         GetDoc() { return (TDocument*)GetValue(); };
  159. };
  160.  
  161.  
  162. inline TDocumentLink::TDocumentLink(TDocumentLink* n, TDocument* v) :
  163.     TLink(n, v)
  164. {}
  165.  
  166. #endif
  167.